<?php

namespace app\model\api;

use laytp\BaseModel;

class MiniType extends BaseModel
{
    /**
     * 一级分类
     * @return MiniType[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getFirstType(){
        return $this->where('p_id',0)->cache(true)->select();
    }

    /**
     * 二级分类
     * @param $p_id
     * @return MiniType[]|array|\think\Collection
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getSecondType($p_id){
        return $this->where('p_id',$p_id)->field('id,name')->cache(true)->select();
    }
}